package com.gnerv.author.controller;


import com.gnerv.author.entity.R;
import com.gnerv.author.entity.User;
import com.gnerv.author.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 基础平台-用户表 前端控制器
 * </p>
 *
 * @author Gnerv LiGen
 * @since 2019-07-15
 */
@CrossOrigin
@RestController
@RequestMapping("/blog/user")
public class UserController {

    @Autowired
    IUserService userService;

    @RequestMapping(value = "create", method = RequestMethod.POST)
    public R create(@RequestBody User user) {
        userService.createUser(user);
        return R.back();
    }

    @RequestMapping(value = "delete/{bId}", method = RequestMethod.GET)
    public R delete(@PathVariable("bId") String bId) {
        userService.deleteUser(bId);
        return R.back();
    }

    @RequestMapping(value = "list", method = RequestMethod.POST)
    public R list(@RequestBody User user) {
        List<User> users = userService.listUser(user);
        return R.back().data("users", users);
    }
}
